type Action<T extends string = string> = {
    type: T;
    [extraProps: string]: any;
};

type ObjectFromFields<T extends readonly string[]> = {
  [K in T[number]]: unknown;
} & {
  type: string;
};

/**
 * @function
 * @description action 函数生成器
 * @param {string} type - action type 类型
 * @param {Array<string>} argNames action对象key - action 其余属性
 * @type {A} dispatch 消费的 `action` 类型
 * @returns {fn} action构建函数
 */
export const actionCreator = <A extends Action>(
  type: A['type'],
  ...lists: Array<string>
) => (...args: Array<any>): A => {
    const action = { type } as any
    lists.forEach((_, index) => {
      const key = lists[index]
      action[key] = args[index]
    })
    return action
  }
